<header class="layout head padding-small">
    <a href="javascript:pageBack();" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">我的收藏</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>
<div class="layout"><!--类别导航S-->
    <div class="container">
        <div class="line margin-top">
            <ul class="x12 text-center list-unstyle custom-b">
                <li id="goods" class="x4 left-yj padding-small select-ys">商品收藏</li><!--背景颜色是.select-ys，字体颜色是.select-zt-->
                <li id="stores" class="x4 zy-border padding-small">商城收藏</li>
                <li id="brands" class="x4 right-yj padding-small">品牌收藏</li>
            </ul>
        </div>
    </div><!--类别导航E-->

    <div class="layout">
        <div id="main" class="container">
            <div id="goods_con" class="twin_con">
                <ul class="list-media margin-top">
                </ul>
                <div class="" style="text-align:center;" id="g_more_hi"><span style="font-size:12px;">加载中...</span></div>
            </div>
            <!--商城收藏 S-->
            <div id="stores_con" class="twin_con" style="display:none;">
                <ul class="list-media margin-top">

                </ul>
                <div class="" style="text-align:center;" id="s_more_hi"><span style="font-size:12px;">加载中...</span></div>
            </div>
            <!--商城收藏 E-->
            <div id="brands_con" class="twin_con" style="display:none;">
                <ul class="list-media margin-top">

                </ul>
                <div class="" style="text-align:center;" id="b_more_hi"><span style="font-size:12px;">加载中...</span></div>
            </div>
        </div><!--container-->
        <input type="hidden" id="gpage" value="1">
        <input type="hidden" id="spage" value="1">
        <input type="hidden" id="bpage" value="1">
    </div><!--layout-->
<script>
    //类别导航S
    $(document).ready(function(){

        //根据收藏类别，来显示对应的收藏列表
        <?php if($_GET['fav_type']=='goods'){$_SESSION['gfavs_click']=true;?>
        getGoods();
        gflag= false;
        <?php }elseif($_GET['fav_type']=='stores'){$_SESSION['sfavs_click']=true;?>
        getStores();
        sflag= false;
        <?php }elseif($_GET['fav_type']=='brands'){$_SESSION['bfavs_click']=true;?>
        getBrands();
        bflag= false;
        <?php }?>

        $('#goods').click(function(){
            getGoods();
            gflag= false;   //点击一次收藏，则为false,表示是第二次点击

        });
        $('#stores').click(function(){
            getStores();
            sflag= false;
        });
        $('#brands').click(function(){
            getBrands();
            bflag= false;
        });


    });
    var GOODSURL = '<?php echo SiteUrl.DS.ATTACH_GOODS.DS;?>';
    var STOREURL = '<?php echo SiteUrl.DS.ATTACH_STORE.DS;?>';
    var BRANDURL = '<?php echo SiteUrl.DS.ATTACH_BRAND.DS;?>';
    var LOADING  = "加载中...";
    var LOADMORE  = "加载更多";
    var LOADEDOUT  = "已没有更多";
    var gflag = true;   //  表示第一次点击商品收藏
    var sflag = true;   //  表示第一次点收藏
    var bflag = true;   //  表示第一次点击收藏
    function getGoods(){
        $(".line ul li").removeClass("select-ys");
        $(".line ul li:eq(0)").addClass("select-ys");
        $("#main .twin_con").hide();
        $("#goods_con").show();
        if(gflag==false)return; //当第二次点击时，不再加载列表
        getGoodsList();
    }
    function getStores(){
        $(".line ul li").removeClass("select-ys");
        $(".line ul li:eq(1)").addClass("select-ys");
        $("#main .twin_con").hide();
        $("#stores_con").show();
        if(sflag==false)return; //当第二次点击时，不再加载列表
        getStoreList();
    }
    function getBrands(){
        $(".line ul li").removeClass("select-ys");
        $(".line ul li:eq(2)").addClass("select-ys");
        $("#main .twin_con").hide();
        $("#brands_con").show();
        if(bflag==false)return; //当第二次点击时，不再加载列表
        getBrandList();
    }

    //加载商品收藏列表的方法 S
    function getGoodsList(){
        if($('#g_more_hi span').text()==LOADEDOUT){return false;}
        $('#g_more_hi span').text(LOADING);
        jQuery.getJSON('index.php?act=member_favorites&op=fglist',{curpage:$('#gpage').val()},function(data){
            var contarea = $("#goods_con ul:eq(0)");
            if(data.state){
                jQuery.each(data.goods_list,function(i,v){
                    var content = '<li class="x12 bg-white radius-big padding"><div> '
                        +'<a href="index.php?act=goods&goods_id=' + v.goods_id +'" class="x10"> '
                        +'<div class="x3"><img class="img-responsive self-motion cp-border layout" src="'+GOODSURL+v.store_id+'/'+v.goods_image+'" onerror="src=\'<?php echo TEMPLATES_PATH;?>/images/html5/default50x50.png\'" /> '
                        +'</div>'
                        +'<ul class="x9 padding-small-left list-unstyle text-small">'

                        +'<li class="goods-name">'+v.goods_name+'</li>'
                        +'<li style="margin:0px;"><strong class="zt_color">&yen;'+v.goods_store_price+'</li>'
                        +'</ul></a>'
                        +'<div class="x2 text-right ljxbj"><i did="'+v.goods_id+'" dtype="goods" class="icon-trash-o"></i></div>'
                        +'</div> '
                        +'</li> ';
                    contarea.append(content);
                });
                $('#g_more_hi span').text(LOADMORE);
                $('#gpage').val(parseInt($('#gpage').val())+1);
            }else{
                if($('#gpage').val()>1){ $('#g_more_hi span').text(LOADEDOUT);return false;}
                $('#g_more_hi').remove();
                var content = '<li class="noTxt"><div class="text-center text-gray padding-large">'
                +' <i class="icon-meh-o"></i><p>您还没有收藏任何商品，<br><a href="index.php?act=official_shop" class="text-ef7f7e">随便逛逛</a>遇到喜欢的要赶紧收藏哦。</p>'
                +' </div> </li>';
                contarea.append(content);
                $('li.noTxt').show();
            }
        });
    }
    $('#g_more_hi').click(function(){
        if($('#g_more_hi span').text()==LOADEDOUT){return false;}
        getGoodsList();
    })

    //加载商城收藏的方法 S
    function getStoreList(){
        if($('#s_more_hi span').text()==LOADEDOUT){return false;}
        $('#s_more_hi span').text(LOADING);
        jQuery.getJSON('index.php?act=member_favorites&op=fslist',{curpage:$('#spage').val()},function(data){
            var contarea = $("#stores_con ul:eq(0)");
            if(data.state){
                jQuery.each(data.store_list,function(i,v){
                    var content = '<li class="x12 bg-white radius-big padding"><div>'
                        +'<a class="x10 padding-small-right" href="index.php?act=show_store&id=' + v.store_id +'"> '
                        +'<div class="x3"><img class="img-responsive self-motion border" src="'+STOREURL+'/'+v.store_logo+'" onerror="src=\'<?php echo TEMPLATES_PATH;?>/images/html5/default50x50.png\'"/> </div>'
                        +'<ul class="x9 list-unstyle text-small padding-small-left">'
                        +'<li class="width">商城名称：'+v.store_name+'</li>'
                        +'<li class="width">所在地：'+v.area_info+'</li>'
                        +' <li style="margin-bottom:0px">会员名称：'+v.member_name+'</li>'
                        +'</ul> </a> <div class="x2 text-right ljxbj"><i did="'+ v.store_id
                        +'" class="icon-trash-o" dtype="store"></i></div> </div></li>'

                    contarea.append(content);
                });
                $('#s_more_hi span').text(LOADMORE);
                $('#spage').val(parseInt($('#spage').val())+1);
            }else{
                if($('#spage').val()>1){ $('#s_more_hi span').text(LOADEDOUT);return false;}
                $('#s_more_hi').remove();
                var content = '<li class="noTxt"><div class="text-center text-gray padding-large">'
                +'<i class="icon-meh-o"></i><p>您还没有收藏任何品牌，<br><a href="index.php" class="text-ef7f7e">随便逛逛</a>遇到喜欢的要赶紧收藏哦。</p>'
                +' </div></li>'
                contarea.append(content);
                $('li.noTxt').show();
            }
        });
    }
    $('#s_more_hi').click(function(){
        if($('#s_more_hi span').text()==LOADEDOUT){return false;}
        getStoreList();
    })

    //品牌列表
    function getBrandList(){
        if($('#b_more_hi span').text()==LOADEDOUT){return false;}
        $('#b_more_hi span').text(LOADING);
        jQuery.getJSON('index.php?act=member_favorites&op=fblist',{curpage:$('#bpage').val()},function(data){
            var contarea = $("#brands_con ul:eq(0)");
            if(data.state){
                jQuery.each(data.brand_list,function(i,v){
                    var content = '<li class="x12 bg-white radius-big padding"> <div> '
                        +'<a class="x10 padding-small-right" href="index.php?act=brand&op=brand_detail&brand_id=' + v.brand_id +'"> '
                        +'<div class="x3"><img src="'+BRANDURL+v.brand_store_id+'/'+v.brand_pic+'"class=" layout" onerror="src=\'<?php echo TEMPLATES_PATH;?>/images/html5/default_brand_image.gif\'" /> </div>'
                        +'<ul class="x9 list-unstyle text-small padding-small-left">'

                        +'<li style="margin-bottom:5px;">品牌名称：'+v.brand_name+'</li>'
                        +'<span class="title">品牌收藏量：'+v.brand_collect+'</span>'
                        +'</ul> </a><div class="x2 text-right ljxbj"><i did="'+v.brand_id+'" class="icon-trash-o" dtype="brands"></i></div></div></li>'
                    contarea.append(content);
                });
                $('#b_more_hi span').text(LOADMORE);
                $('#bpage').val(parseInt($('#bpage').val())+1);
            }
            else{
                if($('#bpage').val()>1){ $('#b_more_hi span').text(LOADEDOUT);return false;}
                $('#b_more_hi').remove();
                var content = ' <li class="noTxt"> <div class="text-center text-gray padding-large">'
                +' <i class="icon-meh-o"></i>'
                +' <p>您还没有收藏任何品牌，<br><a href="index.php?act=brand" class="text-ef7f7e">随便逛逛</a>遇到喜欢的要赶紧收藏哦。</p>'
                +'</div></li>';
                contarea.append(content);
                $('li.noTxt').show();
            }
        });
    }
    //加载更多品牌收藏
    $('#b_more_hi').click(function(){
        if($('#b_more_hi span').text()==LOADEDOUT){return false;}
        getBrandList();
    })
    //删除收藏
        $(".icon-trash-o").live('click',function(){
            var fav_id = jQuery(this).attr("did").trim();
            var type = jQuery(this).attr("dtype").trim();
            if(type=='brands'){
                if (confirm("确定要取消该收藏吗？")){
                    jQuery.getJSON("index.php?act=member_favorites&op=delfavoritesbrand",{"fav_id":fav_id},
                        function(data){
                            if(data.done){
                               // alert(data.msg);
                                location.reload(true);
                                return false;
                            }else{
                                alert(data.msg);
                                return false;
                            }
                        });
                } else {
                    return false;
                }
            }
            if (confirm("确定要取消该收藏吗？")){
                jQuery.getJSON("index.php?act=member_favorites&op=ajaxDelFavorites",{"fav_id":fav_id,"type":type},
                    function(data){
                        if(data.done){
                            //alert(data.msg);
                            location.reload(true);
                        }else{
                            alert(data.msg);
                        }
                    });
            }
            else
            {
                return false;
            }
        });


</script>